﻿@model Inscriptionem.Models.Blog.Views.BlogViewModel

@{
    var article = Model.Articles.FirstOrDefault();
    
    ViewBag.Title = Inscriptionem.Configuration.Configuration.Instance.General.Title + " » " + Model.SectionLocalizedName  + (article != null ? (" » " + article.Title) : string.Empty);
    ViewBag.SearchText = "Search";
    Layout = "Layout.cshtml";

    int currentPage = Model.ID + 1;
    int totalPages = (Model.Articles.Count() / Inscriptionem.Configuration.Configuration.Instance.Blog.PageSize) + 1;
}

<div class="outer" id="contentwrap">
    <div class="sidecont">
		<div class="sidebar sidebar-left">
		    @{Html.RenderPartial("Controls/LeftMenu", Model);}
			<div class="sidebaradbox"></div>
		</div>
    </div>
    <div class="postcont">
		<div id="content">
        @if (article != null)
        {
            var articleURL = string.Format("/{0}/{1}/{2}/{3}",
            Model.Language,
            Model.Section,
            article.Type.ToString(),
            article.ID);
                
            <text>
            <div class="post type-post status-publish format-standard hentry" id="post-@article.ID">
                <h2 class="title">@article.Title</h2>
                <div class="postdate">
                    <img src="/Content/Themes/General/Images/date.png"> @article.CreatedDate.ToShortDateString()
                    <img src="/Content/Themes/General/Images/folder.png"> 

                    @if (article.Categories.Any())
                    {
                        var categoriesList = new List<string>();   
                        foreach (var category in article.Categories.OrderBy(c => c.ID))
                        {
                            categoriesList.Add(string.Format("<a href=\"/{0}/{1}/Category/{2}\" title=\"View all posts in {3}\" rel=\"category tag\">{3}</a>",
                                Model.Language,
                                Model.Section,
                                category.ID,
                                category.Name));
                        }
                        <text>@Html.Raw(string.Join(", ", categoriesList.ToArray()))</text>
                    }
                </div>
                    
                <div class="entry">
                <p></p>
                @{
                    <text>@Html.Raw(article.Content)</text>
                }
	            </div>

                <div class="postdate-single-2">
                @if (article.Tags.Any())
                {
                    <text><img src="/Content/Themes/General/Images/tag.png"> Tags: </text>
                        
                    var tagsList = new List<string>();
                    foreach (var tag in article.Tags.OrderBy(c => c.ID))
                    {
                        tagsList.Add(string.Format("<a href=\"/{0}/{1}/Tag/{2}\" rel=\"tag\">{3}</a>",
                            Model.Language,
                            Model.Section,
                            tag.ID,
                            tag.Name));
                    }
                    <text>@Html.Raw(string.Join(", ", tagsList.ToArray()))</text>
                }
                </div>

                @{Html.RenderPartial("Controls/PostNavigation",
                    new Inscriptionem.Models.Blog.Views.Controls.PostNavidationViewModel(article.ID)
                        {
                        Section = Model.Section,
                        Language = Model.Language   
                    });
                }
			</div>

            @{Html.RenderPartial("Controls/Comments",
                new Inscriptionem.Models.Blog.Views.Controls.CommentsViewModel(article)
                {
                    Section = Model.Section,
                    Language = Model.Language
                });
            }

	        <div class="navigation">
		        <div class="alignleft"></div>
		        <div class="alignright"></div>
	        </div>

            <div id="respond">
                @if (Inscriptionem.Authorization.Member.Current.ID != 0 && article.IsCommentable && Inscriptionem.Controllers.BlogController.IsCommentsAllowed)
                {
                <text>
                <h3>Leave a Reply</h3>
                <form action="/@Model.Language/@Model.Section/@article.Type.ToString()/@article.ID" method="post" id="commentform">
                    <p>
                        <textarea name="Comment" id="comment" cols="100%" rows="10" tabindex="1"></textarea>
                    </p>
                    <p>
                        <input type="hidden" name="ID" value="@article.ID" id="ID">
                        <input name="submit" type="submit" id="submit" tabindex="2" value="Submit Comment">
                    </p>
                </form>
                </text>
                }
                else if (Inscriptionem.Authorization.Member.Current.ID == 0)
                {
                <text>
                <h3 style="text-align: center;">Please <a href="/@Model.Language/Login">log in</a> or <a href="/@Model.Language/Login/Register">register</a> to leave a reply.</h3>
                </text>
                }
                else
                {
                <text>
                <h3 style="text-align: center;">Comments are disabled, or you don't have permission to write one.</h3>
                </text>
                }
			</div>
            </text>
        }
        else
        { 
            <text>
            <div style="width: 100%;">
                <h2 style="text-align: center !important; color: #AF3530 !important;">Nothing to display</h2>
            </div>
            </text>
        }
        </div>
	</div>	
	<div class="sidecont rightsector">
		<div class="sidebar sidebar-right">
            @{Html.RenderPartial("Controls/RightMenu", Model);}
		    <div class="sidebaradbox"></div>
		</div>
	</div>
</div>